package cn.farm.farm.Controller.OrdinaryController;

import cn.farm.farm.MessageModel.Common;
import cn.farm.farm.Util.file.OssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;

@Controller
@Slf4j
public class TestController {

    final String servername = "ordinary";

    @ResponseBody
    @RequestMapping("ping")
    public Common upload(HttpSession session){
        log.info("success ping " + servername);
        //据我发现 必须操作下Session响应头才会有Set-Cookie
        session.setAttribute("status","success get session");
        return new Common(200,"success ping "+servername);
    }

    @ResponseBody
    @PostMapping("upload")
    public Common uploadImage(MultipartFile image){
        String uploadFile = OssUtil.uploadImage(image);
        return new Common(200,uploadFile);
    }


    @PostMapping("test")
    public String test(){

        return "noLogin";
    }


}
